-- @Author: baidwwy
-- @Date:   2018-04-10 22:48:47
-- @Last Modified by:   baidwwy
-- @Last Modified time: 2018-05-12 20:53:47


local logger = class()
local ffi = require( "ffi" )
ffi.cdef[[
    int     _access(const char*, int);
    void*   ILogger_Create();
    int     ILogger_Init(void*,const char*,int,int);
    void    ILogger_Log_0(void*,int,const char*);
    int     ILogger_UnInit(void*);
    void    ILogger_Destroy(void*);
]]

local Logdll
if ffi.C._access(__gge.runpath.."/模块/Logger.dll",0) == 0 then
    Logdll = ffi.load("./模块/Logger.dll")
else
    Logdll = ffi.load("Logger.dll")
end

function logger:初始化(文件)
    if type(文件) == 'number' then
        self._log  = ffi.cast("void*",文件)
    else
        self._log  = Logdll.ILogger_Create()
        self.isok = Logdll.ILogger_Init(self._log,文件 or  "",__gge.isdebug and 1 or 3,1)
    end
end
function logger:销毁()--logger不能自动销毁
    Logdll.ILogger_UnInit(self._log)
    Logdll.ILogger_Destroy(self._log)
end
function logger:取指针()
    return tonumber(ffi.cast("intptr_t",self._log))
end
local ltype = {
    DEBUG=1,TRACE=2,INFO=3,WARN=4,ERROR=5,FATAL=6
}
function logger:LOGS(str,t)--通用
    Logdll.ILogger_Log_0(self._log,ltype[t] or 3,tostring(str))
end
function logger:DEBUG(str)--调试(游戏编译后,会无效)
    Logdll.ILogger_Log_0(self._log,1,tostring(str))
end
function logger:TRACE(str)--追踪(游戏编译后,会无效)
    Logdll.ILogger_Log_0(self._log,2,tostring(str))
end
function logger:INFO(str)--信息
    Logdll.ILogger_Log_0(self._log,3,tostring(str))
end
function logger:WARN(str)--警告
    Logdll.ILogger_Log_0(self._log,4,tostring(str))
end
function logger:ERROR(str)--错误
    Logdll.ILogger_Log_0(self._log,5,tostring(str))
end
function logger:FATAL(str)--致命
    Logdll.ILogger_Log_0(self._log,6,tostring(str))
end

return logger